namespace SimpleWebServices.Xml
{
    using System;
    using System.Xml;
    using System.Xml.XPath;
    using SimpleWebServices;
    using Xunit;

    public sealed class XmlDocumentExtensionMethodsFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(typeof(XmlDocumentExtensionMethods).IsStatic());
        }

        [Fact]
        public void op_ToXmlAttribute_XmlDocumentNull_string_string()
        {
            Assert.Throws<ArgumentNullException>(() => (null as XmlDocument).ToXmlAttribute("name", "value"));
        }

        [Fact]
        public void op_ToXmlAttribute_XmlDocument_stringNull_string()
        {
            Assert.Throws<ArgumentNullException>(() => new XmlDocument().ToXmlAttribute(null as string, "value"));
        }

        [Fact]
        public void op_ToXmlAttribute_XmlDocument_stringEmpty_string()
        {
            Assert.Throws<ArgumentException>(() => new XmlDocument().ToXmlAttribute(string.Empty, "value"));
        }

        [Fact]
        public void op_ToXmlAttribute_XmlDocument_string_stringNull()
        {
            Assert.Null(new XmlDocument().ToXmlAttribute("name", null as string));
        }

        [Fact]
        public void op_ToXmlAttribute_XmlDocument_string_string()
        {
            XmlAttribute actual = new XmlDocument().ToXmlAttribute("name", "value");

            Assert.Equal<string>("name", actual.Name);
            Assert.Equal<string>("value", actual.Value);
        }

        [Fact]
        public void op_ToXmlAttribute_XmlDocument_string_stringEmpty()
        {
            XmlAttribute actual = new XmlDocument().ToXmlAttribute("name", string.Empty);

            Assert.Equal<string>("name", actual.Name);
            Assert.Equal<string>(string.Empty, actual.Value);
        }

        [Fact]
        public void op_ToXmlNode_XmlDocumentNull_string_string()
        {
            Assert.Throws<ArgumentNullException>(() => (null as XmlDocument).ToXmlNode("name", "value"));
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_stringNull_string()
        {
            Assert.Throws<ArgumentNullException>(() => new XmlDocument().ToXmlNode(null as string, "value"));
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_stringEmpty_string()
        {
            Assert.Throws<ArgumentException>(() => new XmlDocument().ToXmlNode(string.Empty, "value"));
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_string_string()
        {
            XmlNode actual = new XmlDocument().ToXmlNode("name", "value");

            Assert.Equal<string>("name", actual.Name);
            Assert.Equal<string>("value", actual.InnerText);
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_string_stringNull()
        {
            XmlNode actual = new XmlDocument().ToXmlNode("name", null as string);

            Assert.Equal<string>("name", actual.Name);
            Assert.Equal<string>(string.Empty, actual.InnerText);
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_string_stringEmpty()
        {
            XmlNode actual = new XmlDocument().ToXmlNode("name", string.Empty);

            Assert.Equal<string>("name", actual.Name);
            Assert.Equal<string>(string.Empty, actual.InnerText);
        }

        [Fact]
        public void op_ToXmlNode_XmlDocumentNull_string_IXPathNavigable()
        {
            Assert.Throws<ArgumentNullException>(() => (null as XmlDocument).ToXmlNode("name", "value".Serialize()));
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_stringNull_IXPathNavigable()
        {
            Assert.Throws<ArgumentNullException>(() => new XmlDocument().ToXmlNode(null as string, "value".Serialize()));
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_stringEmpty_IXPathNavigable()
        {
            Assert.Throws<ArgumentException>(() => new XmlDocument().ToXmlNode(string.Empty, "value".Serialize()));
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_string_IXPathNavigable()
        {
            XmlNode actual = new XmlDocument().ToXmlNode("name", "value".Serialize());

            Assert.Equal<string>("name", actual.Name);
            Assert.True((bool)actual.CreateNavigator().Evaluate("1 = count(/string[text()='value'])"));
        }

        [Fact]
        public void op_ToXmlNode_XmlDocument_string_IXPathNavigableNull()
        {
            XmlNode actual = new XmlDocument().ToXmlNode("name", null as IXPathNavigable);

            Assert.Equal<string>("name", actual.Name);
            Assert.Equal<string>(string.Empty, actual.InnerXml);
        }
    }
}